package com.inspector.app.ui.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;


import com.example.commen.base.UCApplication;
import com.inspector.app.BaseApp;
import com.inspector.app.R;


/**
 * @author zlq
 * @date 2019/6/18
 */
public class ExitSettingDialog extends Dialog {
    TextView content, cancel, submit;
    Context context;

    public ExitSettingDialog(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        LayoutInflater layoutInflater = LayoutInflater.from(UCApplication.getContext());
        View view = layoutInflater.inflate(R.layout.dialog_custom_delete, null);
        setContentView(view);
        findView(view);

    }

    private void findView(View view) {
        cancel = view.findViewById(R.id.cancel);
        submit = view.findViewById(R.id.submit);
        content = view.findViewById(R.id.content);
        content.setText(R.string.exit_setting);

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                BaseApp.getInstance().loginOut();
            }
        });
    }

    private void initView() {
        Window dialogWindow = this.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        DisplayMetrics d = getContext().getResources().getDisplayMetrics(); // 获取屏幕宽、高用
        lp.width = (int) (d.widthPixels * 0.7);
        dialogWindow.setAttributes(lp);
    }

}
